package com.cqw.commontest.thread.unit4;

import java.util.concurrent.*;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-06-07 15:30
 * @Description: 线程池
 */
public class Test1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                5,
                10,
                1L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(100),
                new ThreadPoolExecutor.CallerRunsPolicy());

        int flag = 1;
        for (int i = 0; i < 10; i++) {
            int finalI = i;
            Future<Integer> submit = executor.submit(() -> {
                return get();
            });
            System.out.println("1334");
            Integer integer = submit.get();
            System.out.println("234");
        }
    }

    private static int get(){
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {

        }
        return 2;
    }


}


class MyRunnable implements Runnable {

    private String command;

    public MyRunnable(String command) {
        this.command = command;
    }

    @Override
    public void run() {
        System.out.println();
    }
}
